!*************************************************************
subroutine den2dden(nx,nz,den,dden,bf_left,bf_right,bf_top,bf_bottom)
integer nx,nz,bf_left,bf_right,bf_top,bf_bottom
integer i,k
real den(1:nx,1:nz)
real den0(0:nx+1,0:nz+1)
real dden(1:nx+1,1:nz+1)
real den1,den2,den3,den4
dden=0.0
den0=0.0
den0(1:nx,1:nz)=den(1:nx,1:nz)
  
do i=1+bf_bottom , nx+1-bf_top
  do k=1+bf_left   , nz+1-bf_right

    den1=den0(i  ,k  )
    den2=den0(i-1,k  )
    den3=den0(i  ,k-1)
    den4=den0(i-1,k-1)
      
    dden(i,k)=den1 - den2 - den3 + den4
  enddo

  write(*,"(i3,a2)",advance="no") (i-1-bf_bottom)*100/(nx-bf_top-bf_bottom),"% "

enddo
end subroutine
!*************************************************************
subroutine mat2vec(nx,nz,den,vec)
integer nx,nz
real den(nx,nz)
real vec(nx*nz)
do i=1,nx
do j=1,nz
        ij=(i-1)*nz+j
        vec(ij)=den(i,j)
enddo
enddo
end subroutine
!*************************************************************

